package BIOtest04;

import java.util.concurrent.*;

/**
 * 线程池有五种状态：
 * Running，Shutdown，stop，tidying，terminated。
 */
public class ServerSocketThreadPool {
    private ExecutorService executorService;
    //初始化创建线程池
    /**
     public ThreadPoolExecutor(int corePoolSize,
     int maximumPoolSize,
     long keepAliveTime,
     TimeUnit unit,
     BlockingQueue<Runnable> workQueue) {
     */
    public ServerSocketThreadPool(){
        executorService = new ThreadPoolExecutor(3,4,10, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>());

    }

    /**
     * executor只能执行Runnable类型的参数
     * 没有返回值
     * 提供一个方法用来提交任务给线程池，暂存或执行
     */
    public void executor(Runnable targer){
        executorService.execute(targer);
    }

    /**
     submit方法可以执行Runnable和Callable类型的参数
     可以获取执行后的返回值
     * @param targer
     */
    public Future<String> submit(Callable<String> targer){
        executorService.submit(targer);
        return null;
    }
}
